package com.ruoyi.mall.app.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.mall.app.service.DtsCommentService;
import com.ruoyi.mall.common.domain.DtsComment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/index/comment")
public class DtsCommentController {

    @Autowired
    private DtsCommentService dtsCommentService;


    @GetMapping("/selComment")
    public AjaxResult selComment(DtsComment dtsComment) {
        List<DtsComment> list = dtsCommentService.selectDtsCommentList(dtsComment);
        if (list != null) {
            return AjaxResult.success(list);
        } else {
            return AjaxResult.error();
        }
    }

    @GetMapping("/addComment")
    public AjaxResult addComment(
            @RequestParam("userId") Integer userId,
            @RequestParam("content") String content,
            @RequestParam("star") Integer star,
            @RequestParam(value = "picUrls", required = false) String picUrls,
            @RequestParam("valueId") Integer valueId,
            @RequestParam("productId") Integer productId,
            @RequestParam("orderId") Long orderId,
            @RequestParam("orderGoodsId") Integer orderGoodsId,
            @RequestParam("type") Integer type) {

        DtsComment dtsComment = new DtsComment();
        dtsComment.setUserId(Long.valueOf(userId));
        dtsComment.setContent(content);
        dtsComment.setStar(star);
        dtsComment.setPicUrls(picUrls); // 可为null
        dtsComment.setValueId(Long.valueOf(valueId));
        dtsComment.setProductId(productId); // 确保实体类有该字段
        dtsComment.setOrderId(orderId);
        dtsComment.setOrderGoodsId(Long.valueOf(orderGoodsId));
        dtsComment.setType(type);

        int i = dtsCommentService.insertDtsComment(dtsComment);
        if (i > 0) {
            return AjaxResult.success(i);
        } else {
            return AjaxResult.error();
        }
    }
}




























